package com.dingwen.treasure.kettle.controller;

import com.dingwen.treasure.kettle.base.controller.BaseViewController;
import com.dingwen.treasure.kettle.base.enums.BaseEnum;
import com.dingwen.treasure.kettle.base.vo.Result;
import com.dingwen.treasure.kettle.utils.EnumUtil;
import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 　EnumController
 * 　@author dingwen
 * 　@date 2022/8/22
 */
@Api(tags = "枚举API")
@RestController
@Slf4j
@RequestMapping("enum")
public class EnumController implements BaseViewController {

    @ApiOperation(value = "获取枚举翻译信息")
    @ApiImplicitParam(name = "enumClassName", value = "枚举类简单名称", paramType = "query")
    @GetMapping()
    @SneakyThrows(Throwable.class)
    @Cacheable(cacheNames = "enum", key = "#root.methodName.concat(':').concat(#enumClassName)")
    public Result<List<Object>> getEnums(@RequestParam(required = false, defaultValue = BaseEnum.ALL) String enumClassName) {
        return success(EnumUtil.getEnumMap(enumClassName));
    }
}
